import store from "../index"
import { http } from "@/request"

let storage = {
  get: ()=>{
    let params = sessionStorage.getItem("activity_type")
    if(params){
      params = JSON.parse(params)
    }
    console.log("storage get ==> ", params);
    
    return params
  }
}

export default {
  state: {
    "activity_type": storage.get()
  },
  getters: {
    "activity_type"(state: any){
      // console.log('state["activity_type"] ==> ', state["activity_type"]);
      if(state["activity_type"]){
        return state["activity_type"]
      }else{
        store.dispatch('getActivityInfo')
      }
    }
  },
  mutations: {
    "activity_type"(state: any, payload: any){
      console.log("mutations ====== ");
      // state['activity_type'] = payload
      payload = JSON.stringify(payload)
      sessionStorage.setItem("activity_type", payload)
    }
  },
  actions: {
    getActivityInfo(context:any){
      http("ACTIVITY_TYPE").then(({result}) => {
        console.log("actions ====== ");
        context.commit("activity_type", result)
      }).catch(err => {
        console.log("err ==> ", err);
      })
    }
  }
}